//
//  HSYBaseVideoPlayerControllerView.m
//  高仿暴走斗图
//
//  Created by key on 16/6/15.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYBaseVideoPlayerControllerView.h"
#import <AVFoundation/AVFoundation.h>
#import "UIView+Gesture.h"

@interface HSYBaseVideoPlayerControllerView ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong, readonly) UISlider *progressSlider;
@property (nonatomic, strong, readonly) UIActivityIndicatorView *activityIndicatorView;

@end

@implementation HSYBaseVideoPlayerControllerView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}


- (void)setup
{
    self.backgroundColor = [UIColor clearColor];
    
    @weakify(self);
    UITapGestureRecognizer *tapGesture = [UIView rad_addTapGestureRecognizerWithDelegate:self numberOfTouchesRequired:1 numberOfTapsRequired:1 selectBlock:^(id x) {
        NSLog(@"x :%@", x);
    }];
    [self addGestureRecognizer:tapGesture];
    
    _bottomBar = [NSObject createViewWithBgColor:[UIColor blackColor]];
    self.bottomBar.frame = CGRectMake(0, self.viewHeight/3*2, self.viewWidth, self.viewHeight/3);
    self.bottomBar.alpha = 0.5f;
    [self addSubview:self.bottomBar];
    
    _progressSlider = [NSObject createSliderWithValue:0.0f minimumValue:0.0f maximumValue:100.0f];
    CGFloat sliderOffset = 5.0f;
    self.progressSlider.frame = CGRectMake(sliderOffset, sliderOffset, self.bottomBar.viewWidth - sliderOffset*2, self.bottomBar.viewHeight - sliderOffset*2);
    [self addSubview:self.progressSlider];
    [[[self.progressSlider rac_signalForControlEvents:UIControlEventValueChanged] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(UISlider *slider) {
        
        @strongify(self);
        CGFloat value = floor(slider.value);
        if (self.sliderDidChange) {
            self.sliderDidChange(value);
        }
    }];
    [[[self.progressSlider rac_signalForControlEvents:UIControlEventTouchDown] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(UISlider *slider) {
        
        @strongify(self);
        if (self.sliderTouchBegan) {
            self.sliderTouchBegan();
        }
        [self cancelAutoFadeOutControlBar];
    }];
    [[[self.progressSlider rac_signalForControlEvents:UIControlEventTouchUpInside] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(UISlider *slider) {
        
        @strongify(self);
        if (self.sliderTouchEnd) {
            self.sliderTouchEnd(slider.value);
        }
        [self autoFadeOutControlBar];
    }];
    [[[self.progressSlider rac_signalForControlEvents:UIControlEventTouchUpOutside] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(UISlider *slider) {
        
        @strongify(self);
        if (self.sliderTouchEnd) {
            self.sliderTouchEnd(slider.value);
        }
        [self autoFadeOutControlBar];
    }];
}


- (void)animateHide
{
    
}

- (void)animateShow
{
    
}

- (void)autoFadeOutControlBar
{
    
}

- (void)cancelAutoFadeOutControlBar
{
    
}


@end
